package com.xinzhi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xinzhi.domain.User;
import com.xinzhi.domain.vo.TopicCondition;
import com.xinzhi.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
public class TopicServiceImpl {
    @Autowired
    UserMapper userMapper;
    @Cacheable(cacheNames = "topics")
    public IPage<User> queryByCondition(TopicCondition con){
        System.out.println("分页");
        Page<User> page = new Page<>();
        page.setCurrent(con.getPageNo());
        page.setSize(con.getPageSize());
        QueryWrapper<User> qw = new QueryWrapper<>();
        if (con.getTopicName() != null && !con.getTopicName().isEmpty()){
            qw.like("topic",con.getTopicName());
        }
        return userMapper.selectPage(page,qw);
    }
}
